#include "mainwindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    this->setGeometry(0, 0, 800, 480);
    mDialogButtonBox = new QDialogButtonBox(this);
    mDialogButtonBox->setGeometry(300, 200, 200, 30);
    mDialogButtonBox->addButton(QDialogButtonBox::Cancel);
    mDialogButtonBox->button(QDialogButtonBox::Cancel)->setText("取消");

    mPushButton = new QPushButton(tr("自定义"));
    mDialogButtonBox->addButton(mPushButton,
                                QDialogButtonBox::ActionRole);

    connect(mDialogButtonBox, &QDialogButtonBox::clicked,
            this, &MainWindow::onDialogButtonClickListener);
}

MainWindow::~MainWindow()
{

}

void MainWindow::onDialogButtonClickListener(QAbstractButton *button)
{
    if (button == mDialogButtonBox->button(QDialogButtonBox::Cancel)) {
        qDebug() << "单击了取消按钮" << endl;
    }
    else if (button == mPushButton) {
        qDebug() << "单击了自定义键" << endl;
    }
}
